﻿Imports System.Xml

Namespace Stories
	Public Class Story
		Public Sub New()
			Me.Children = New List(Of Child)
		End Sub

		Public Overrides Function ToString() As String
			Return Me.Self
		End Function

		Property AppliedNamedGrid As String

		Property AppliedTOCStyle As String

		Property StoryTitle As String

		Property TrackChanges As Boolean?

		Property Self As String

		Property StoryPreference As StoryPreference

		Property InCopyExportOption As InCopyExportOption

		Property Children As List(Of Child)

		Public Shared Function ReadXml(reader As XmlReader) As Story
			Dim s As New Story()

			s.Self = reader.GetAttribute("Self")
			s.AppliedNamedGrid = reader.GetAttribute("AppliedNamedGrid")
			s.AppliedTOCStyle = reader.GetAttribute("AppliedTOCStyle")
			s.StoryTitle = reader.GetAttribute("StoryTitle")
			s.TrackChanges = Parser.ParseBoolean(reader.GetAttribute("TrackChanges"))

			While reader.Read()
				Select Case reader.Name

					Case "ParagraphStyleRange"
						s.Children.Add(ParagraphStyleRange.ReadXml(reader))
					Case "StoryPreference"
						s.StoryPreference = StoryPreference.ReadXml(reader)
					Case "InCopyExportOption"
						s.InCopyExportOption = InCopyExportOption.ReadXml(reader)
					Case "XMLElement"
						s.Children.Add(Stories.XmlElement.ReadXml(reader))
					Case "Content"
						s.Children.Add(New Content(reader.ReadString()))
					Case "Br"
						s.Children.Add(New Br())
					Case "Story"
						If reader.NodeType = XmlNodeType.EndElement Then Exit While
					Case Else
						Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "Story")
				End Select
			End While

			Return s
		End Function
	End Class
End Namespace